$(document).ready(function(){
	$("#queryBtn").click(function(){
		$("#queryForm").submit();
	});
	
	//清空			 		 
	$("#clean").click(function(){
		$("#customerId")[0].value="";
		$("#contact")[0].value="";
		$("#phone")[0].value="";
		$("#email").val("");
	});
	
});

//前往客户详情界面
function goCustomerDetail(customId) {
	var customerType = $('#customerType').val();
	url = "../../../page/goCustomerDetails?customId=" + customId+"&customerType=" + 1;
	window.open(url);
}
function bathApprove(isEffect){
	
	var cusIdStr="";
	var list = $("input[id^=bath_][type='checkbox']:checked");
	if(list.length>0){
		for(var int = 0; int < list.length; int++){
			var id = list[int].id.replace("bath_","");
			if(cusIdStr==""){
				cusIdStr=id;
			}else{
				cusIdStr = cusIdStr+","+id;
			}	
		}
		
	}
	if(cusIdStr==""){
		alert("请选择记录!");
		return;
	}
	 $("#idStr").val(cusIdStr);
	 $("#approveIsEffect").val(isEffect);
	 
	 //$("#approveForm").attr('action',"../../../ruleSet/approval/customDeployApproval/bathApproval");
	 
	 //$("#approveForm").submit();
	 
		var url = "../../../ruleSet/approval/customDeployApproval/bathApproval";
		 $.ajax({
	         type: "POST",
	         dataType:"json",
	         url:url,
	         data:$("#approveForm").serialize(),
	         async: false,
	         error: function(request) {
	             alert("Connection Error !");
	         },
	         success: function(data){
	        	 if(data=="1"){
	        		 alert("审批成功!"); 
	        	 }else{
	        		 alert("审批成功(审批记录有已被其他人审批的记录或流走的客户!)"); 
	        	 }
	        	 $("#redirectForm").submit(); 
	         }
	     }); 
	 
	 
	
}

function bathAllApprove(isEffect,cusIdStrs){
	
	if(cusIdStrs==""){
		alert("无数据，无法审核！");
	}
	 $("#idStr").val(cusIdStrs);
	 $("#approveIsEffect").val(isEffect);
	 
	 //$("#approveForm").attr('action',"../../../ruleSet/approval/customDeployApproval/bathApproval");
	 
	 //$("#approveForm").submit();
	 
	var url = "../../../ruleSet/approval/customDeployApproval/bathApproval";
	 $.ajax({
         type: "POST",
         dataType:"json",
         url:url,
         data:$("#approveForm").serialize(),
         async: false,
         error: function(request) {
             alert("Connection Error !");
         },
         success: function(data){
        	 if(data=="1"){
        		 alert("审批成功!"); 
        	 }else{
        		 alert("审批成功(审批记录有已被其他人审批的记录或流走的客户!)"); 
        	 }
        	 $("#redirectForm").submit(); 
         }
     }); 
}

function approve(id,isEffect,productId,productCode){
	$("#approveCusId").val(id);
	$("#approveIsEffect").val(isEffect);
	$("#productId").val(productId);
	$("#productCode").val(productCode);
	
	var url = "../../../ruleSet/approval/customDeployApproval/approval";
	 $.ajax({
         type: "POST",
         dataType:"json",
         url:url,
         data:$("#approveForm").serialize(),
         async: false,
         error: function(request) {
             alert("Connection Error !");
         },
         success: function(data){
        	 if(data=="1"){
        		 alert("审批成功!"); 
        	 }else if(data=="0"){
        		 alert("客户已流走,已经有其他人审批此记录!"); 
        	 }else if(data=="2"){
        		 alert("客户已流走,或已经有其他人审批此记录!!"); 
        	 }else if(data=="3"){
        		 alert("审批异常!"); 
        	 }
        	 $("#redirectForm").submit(); 
         }
     }); 	
}
function selectAll(){
	if($("#selectAll").attr("checked")==true){
		$('input[id^=bath_]').attr("checked",true); 
	}else{
		$('input[id^=bath_]').attr("checked",false); 
	}
}
